
<template>
    <div class="normal-container">
        <div>
            <div class="normal-text">{{ $route.name }}</div>
            <div class="content-main">
                <section>
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="端子型号">
                            <el-input v-model="formInline.norm" placeholder="请输入端子型号" clearable></el-input>
                        </el-form-item>
                        <el-form-item label="制造编号">
                            <el-input v-model="formInline.code" placeholder="请输入制造编号" clearable></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" class="noraml-btn" @click="getList(true)">查询</el-button>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="noraml-btn" @click="Export"
                                v-loading.fullscreen.lock="fullscreenLoading">导出EXCEL</el-button>
                        </el-form-item>
                    </el-form>
                </section>
                <section>
                    <div
                        style="display: flex;justify-content: flex-end;font-size: 13px;margin-bottom: 10px;align-items: center;">
                        <div style="display: flex;align-items: center;">
                            <div
                                style="width: 11px;height: 11px;border: 1px solid #FF8E8E;background-color: #FFEEEE;margin-right: 5px;">
                            </div>
                            <div>
                                钳口更换预警
                            </div>
                        </div>
                    </div>
                    <el-table v-loading="loading" :row-class-name="tableRowClassName" ref="tableMain" :header-cell-style="{
                        'text-align': 'center',
                        background: '#F6F7FB',
                        color: '#4B4B4B',
                        fontSize: '13px',
                    }" :cell-style="{ 'text-align': 'center' }" :data="tableData" style="width: 100%"
                        :max-height="tableHeight">
                        <el-table-column type="index" label="序号" width="50"></el-table-column>
                        <el-table-column prop="type" label="类别"></el-table-column>
                        <el-table-column prop="code" label="制造编号"></el-table-column>
                        <el-table-column prop="norm" label="端子型号"></el-table-column>
                        <el-table-column prop="manufacturer" label="生产商"></el-table-column>
                        <el-table-column prop="num" label="数量"></el-table-column>
                        <el-table-column prop="entryDate" label="入厂日期"></el-table-column>
                        <el-table-column prop="life" label="使用年限"></el-table-column>
                        <el-table-column prop="userDepar" label="使用部门"></el-table-column>
                        <el-table-column prop="serInter" label="保养周期"></el-table-column>
                        <el-table-column prop="order" label="附件">
                            <template slot-scope="scope">
                                <img @click="showSerInter = true; id = scope.row.id" v-if="scope.row.sum"
                                    src="@/assets/icon/文件.png" style="cursor: pointer;" alt="">
                                <img v-else src="@/assets/icon/附件-灰色.png" style="cursor: not-allowed;" alt="">

                            </template>
                        </el-table-column>
                        <el-table-column prop="remark" label="备注"></el-table-column>
                        <el-table-column prop="order" label="状态" width="100">
                            <template slot-scope="scope">
                                <div class="is-useing" v-if="scope.row.status">在用</div>
                                <div class="is-no-seing" v-else>报废</div>
                            </template>
                        </el-table-column>
                        <el-table-column prop="maxNext" label="最大压接次数"></el-table-column>
                        <el-table-column prop="useNext" label="使用次数"></el-table-column>
                        <el-table-column fixed="right" label="操作"  width="120">
                            <template slot-scope="scope">
                                <el-tooltip content="更换" placement="top-start" effect="light">
                                    <img style="cursor: pointer;margin-right: 10px;" @click="clickChange(scope.row)" src="@/assets/icon/icon-换号.png" alt="">
                                </el-tooltip>
                                <el-tooltip content="更换日志" placement="top-start" effect="light">
                                    <img style="cursor: pointer;" @click="clickDetail(scope.row)" src="@/assets/icon/更换日志.png" alt="">
                                </el-tooltip>
                            </template>
                        </el-table-column>
                    </el-table>
                </section>
                <section style="text-align:center;padding-top:20px">
                    <el-pagination background @current-change="handleCurrentChange" :page-size="pageForm.size"
                        :current-page="pageForm.current" layout="prev, pager, next" :total="total">
                    </el-pagination>
                </section>
            </div>
        </div>
        <el-dialog class="messageDialog" title="" :visible.sync="messageDialog" width="500px">
            <div style="text-align: center;">
                <span style="font-size: 20px;color: #3F3F3F;">系统提示</span>
                <div style="margin-top: 30px;display: flex;text-align: center;margin-left: 30px;">
                    <div>
                        <img style="vertical-align: middle;" src="@/assets/icon/系统提示.png" alt=""><span
                            style="margin-left: 10px;font-size: 17px;color: #000;">确定要为此模具更换钳口吗？</span>
                    </div>
                </div>
                <div class="dialog-footer" style="margin-top: 30px;text-align: right;">
                    <el-button class="noraml-btn" @click="messageDialog = false">取 消</el-button>
                    <el-button class="noraml-btn" type="primary" @click="save">确 定</el-button>
                </div>
            </div>
        </el-dialog>
        <detail v-if="showDetail" :showDetail="showDetail" :detailItem="detailItem" @closeformReason="showDetail = false"></detail>
        <serInterItem v-if="showSerInter" :genre="0" :showSerInter="showSerInter" :id="id" @closeSerInter="showSerInter = false;id = ''"></serInterItem>
    </div>
</template>
  
<script>
import detail from './detailDialog.vue'
import serInterItem from '@/components/serInterDialog.vue'
export default {
    components: { serInterItem,detail },
    data() {
        return {
            showDetail:false,
            showSerInter:false,
            fullscreenLoading:false,
            messageDialog: false,
            total: 0,
            loading: false,
            formInline: {
                code: '',
                norm: '',
            },
            pageForm: {
                current: 1,
                size: 20
            },
            tableData: [],
            tableHeight: 500,
            item: '',
            detailItem: ''
        }
    },
    mounted() {
        this.getDept();
        this.getList();
        this.$nextTick(res => {
            const tableHeight = document.documentElement.clientHeight;
            const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 115;
            this.tableHeight = tableHeight - topHeight;
        })
    },
    computed: {
        listenHeight() {
            return this.$store.state.user.heightSize
        }
    },
    watch: {
        listenHeight(val) {
            const tableHeight = document.documentElement.clientHeight;
            const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 115;
            this.tableHeight = tableHeight - topHeight;
        }
    },
    methods: {
        clickDetail(item) {
            this.detailItem = item;
            this.showDetail = true;
        },
        clickChange(item) {
            if(item.useNext == 0) {
                this.$message.warning('钳口使用次数为0 ，不可更换')
                return;
            }
            this.item = item;
            this.messageDialog = true;
        },
        Export() {
            this.fullscreenLoading = true;
            this.methExportExcel("post", "/mold/mold/expJawReplace", this.formInline, "钳口更换").then((res) => {
                this.fullscreenLoading = res;
            });

        },
        getDept() {
            return new Promise(resolve => {
                this.$baseRequestGet('/sys/dict/getList/4', {}, 'get').then(res => {
                    this.options = res.data;
                    resolve();
                })
            })

        },
        tableRowClassName({ row, rowIndex }) {
            if (row.alarm) {
                return 'warning-row';
            }
            return '';
        },
        save() {
            this.messageDialog = false;
            this.$baseRequest('/mold/replace-record/create',{moldId: this.item.id,maxNext: this.item.maxNext,useNext: this.item.useNext},{},'post').then(res => {
                this.$message.success('更换成功');
                this.getList();
            })
        },
        getList(isClear) {
            this.loading = true;
            if (isClear) this.pageForm.current = 1; // 点击搜索
            this.$baseRequest("/mold/mold/jawReplace", this.formInline, this.pageForm, "post").then(
                (res) => {
                    this.tableData = res.data.records;
                    this.total = Number(res.data.totalRow);
                    this.loading = false;
                }
            ).catch(res => {
                this.loading = false;
            })
        },
        handleCurrentChange(val) {
            this.pageForm.current = val;
            this.getList();
        },
    }
}
</script>
  
<style lang="scss" scoped>
.content-main {
    border: 1px solid #DFE2E8;
    padding: 30px;
    background-color: #fff;
}

.is-useing {
    color: #00B42A;
    position: relative;
}

.is-useing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #00B42A;
}

.is-no-seing {
    color: #FF7D00;
    position: relative;
}

.is-no-seing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #FF7D00;
    
}
</style>
  